% Plot log10(coinc2_f_ratio) as a Mollweide projection
  % define the map structure:
    projectionType = 'mollweid';
    mapstruct = defaultm(projectionType);
    mapstruct.angleunits = 'degrees';
    mapstruct.origin = [0 0 0];
    mapstruct.falseeasting = 0;
    mapstruct.falsenorthing = 0;
    mapstruct.scalefactor = 1;
    
    % load the worldmap coastlines:
    load coast;
    [xc, yc] = mfwdtran(mapstruct, lat, long);
  

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%% 2 IFO Combinations %%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure(1); clf; 
    xproject( skyPositions, coinc2_f_ratio, projectionType );
    maxVal = max(coinc2_f_ratio);
    minVal = min(coinc2_f_ratio);
    avgVal = mean(coinc2_f_ratio);

    hold on;
    plot(xc, yc, 'k-', 'LineWidth', 0.2); % coastlines
    
    % Plot the locations of all the detectors on top of this
    for j=1:4
       det = LoadDetectorData( detNames{j} );
       [x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    end
    hold off;
    colorbar;
    caxis([0.0, max(coinc2_f_ratio)]);
    
    xlabel('\phi / rad', 'FontSize', 14);
    ylabel('\theta / rad', 'FontSize', 14);
    titleText = sprintf('Improvement in 2-IFO coincidence search--aaaa\n Min=%.2f Max = %.2f Mean = %.2f', minVal, maxVal, avgVal)
    title(titleText, 'FontSize', 12);
    set(gca, 'FontSize', 12);
    box on;
    print('-dpng', 'coinc2_f_ratio_aaaa.png')

% Plot log10(rmax2_HLV and HLVI) out as a Mollweide projection
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure(2); clf; 

    subplot 211
    	xproject( skyPositions, log10(rmax2_coinc_HLV), projectionType ); 
    	maxVal = max(rmax2_coinc_HLV);
    	minVal = min(rmax2_coinc_HLV);
    	avgVal = mean(rmax2_coinc_HLV);

	caxMax = max([log10(rmax2_coinc_HLV)  log10(rmax2_coinc_HLVI) ]);
	caxMin = min([log10(rmax2_coinc_HLV)  log10(rmax2_coinc_HLVI) ]);

    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    	for j=1:4
       		det = LoadDetectorData( detNames{j} );
       		[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       		plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10}(r_{max}/Mpc)in a 2-IFO coincident search (HLV)--aaa \n Min=%.2f Max = %.2f Mean = %.2f', minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;

    subplot 212
    	xproject( skyPositions, log10(rmax2_coinc_HLVI), projectionType ); 
    	maxVal = max(rmax2_coinc_HLVI);
    	minVal = min(rmax2_coinc_HLVI);
    	avgVal = mean(rmax2_coinc_HLVI);

    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    	for j=1:4
       		det = LoadDetectorData( detNames{j} );
       		[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       		plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    	end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 2-IFO coincident search (HLVI)--aaaa\n Min=%.2f Max = %.2f Mean = %.2f', minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;
    print('-dpng', 'rmax2_coinc_aaaa.png')

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%% 3 IFO Combinations %%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  %Plotting HLV coinceident search with 3-1FO
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure(3); clf; 

    caxMax = max ([ log10(rmax3.HLV) log10(rmax3.HLI) log10(rmax3.LVI) log10(rmax3.HVI)]);
    caxMin = min ([ log10(rmax3.HLV) log10(rmax3.HLI) log10(rmax3.LVI) log10(rmax3.HVI)]);
    
    subplot 221
	
    	xproject( skyPositions, log10(rmax3.HLV), projectionType ); 
    	maxVal = max(rmax3.HLV);
    	minVal = min(rmax3.HLV);
    	avgVal = mean(rmax3.HLV);
    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 3-IFO coincident search (HLV)--aaa \n Min=%.2f Max = %.2f Mean = %.2f', 		minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;

   %Plotting HLI coinceident search with 3-1FO
    subplot 222
    	xproject( skyPositions, log10(rmax3.HLI), projectionType ); 
    	maxVal = max(rmax3.HLI);
    	minVal = min(rmax3.HLI);
    	avgVal = mean(rmax3.HLI);
        hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
   	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
      			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 3-IFO coincident search (HLI)--aaa\n Min=%.2f Max = %.2f Mean = %.2f', 		minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
   	set(gca, 'FontSize', 12);
    	box on;
    
    	%Plotting LVI coinceident search with 3-1FO
 
    subplot 223	
    	xproject( skyPositions, log10(rmax3.LVI), projectionType ); 
    	maxVal = max(rmax3.LVI);
    	minVal = min(rmax3.LVI);
    	avgVal = mean(rmax3.LVI);
    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin, caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 3-IFO coincident search (LVI)--aaa \n Min=%.2f Max = %.2f Mean = %.2f', 		minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;
    	
    %Plotting HVI coinceident search with 3-1FO
    subplot 224
    	xproject( skyPositions, log10(rmax3.HVI), projectionType ); 
    	maxVal = max(rmax3.HVI);
    	minVal = min(rmax3.HVI);
    	avgVal = mean(rmax3.HVI);
    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
   	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 3-IFO coincident search (HVI)--aaa \n Min=%.2f Max = %.2f Mean = %.2f', 		minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);       
    	set(gca, 'FontSize', 12);
    	box on;
    print('-dpng', 'rmax3_coinc.comb_aaaa.png')

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    figure(4); clf; 

    caxMax = max ([ log10(rmax3_coinc_HLV) log10(rmax3_coinc_HLVI) ]);
    caxMin = min ([ log10(rmax3_coinc_HLV) log10(rmax3_coinc_HLVI) ]);

    subplot 211
	xproject( skyPositions, log10(rmax3.HLV), projectionType ); 
        maxVal = max(rmax3.HLV);
    	minVal = min(rmax3.HLV);
    	avgVal = mean(rmax3.HLV);
    	hold on;


    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10} (r_{max}/Mpc) in a 3-IFO coincident search (HLV)--aaa\n Min=%.2f Max = %.2f Mean = %.2f', minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;

    subplot 212
    	xproject( skyPositions, log10(rmax3_coinc_HLVI), projectionType ); 
    	maxVal = max(rmax3_coinc_HLVI);
    	minVal = min(rmax3_coinc_HLVI);
    	avgVal = mean(rmax3_coinc_HLVI);
    	hold on;
    	plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    	% Plot the locations of all the detectors on top of this
    		for j=1:4
       			det = LoadDetectorData( detNames{j} );
       			[x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       			plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    		end
    	hold off;
    	colorbar;
    	caxis([caxMin caxMax]);
    	xlabel('\phi / rad', 'FontSize', 14);
    	ylabel('\theta / rad', 'FontSize', 14);
    	titleText = sprintf('log_{10}(r_{max}/Mpc) in a 3-IFO coincident search (HLVI)--aaaa \n Min=%.2f Max = %.2f Mean = %.2f', 		minVal, maxVal, avgVal)
    	title(titleText, 'FontSize', 12);
    	set(gca, 'FontSize', 12);
    	box on;
    print('-dpng', 'rmax3_coinc_aaaa.png')
   
	% Plot coinc3_f_ratio as a Mollweide projection
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure(5); clf; 
    xproject( skyPositions, log2(coinc3_f_ratio), projectionType ); 
    maxVal = max(coinc3_f_ratio);
    minVal = min(coinc3_f_ratio);
    avgVal = mean(coinc3_f_ratio);

    hold on;
    plot(xc, yc, 'k-', 'LineWidth', 0.2);
    
    % Plot the locations of all the detectors on top of this
    for j=1:4
       det = LoadDetectorData( detNames{j} );
       [x, y] = mfwdtran(mapstruct, det.phi, det.lambda);
       plot( x, y, 'mo', 'MarkerFaceColor', 'm', 'MarkerSize', 8);
    end
    hold off;
    colorbar;
    caxis([0.0, log2(maxVal)]);
    xlabel('\phi / rad', 'FontSize', 14);
    ylabel('\theta / rad', 'FontSize', 14);
    titleText = sprintf('Improvement in 3-IFO coincidence search log_{2}--aaaa\n Min=%.2f Max = %.2f Mean = %.2f', minVal, maxVal, avgVal)
    title(titleText, 'FontSize', 12);
    set(gca, 'FontSize', 12);
    box on;
    print('-dpng', 'coinc3_f_ratio_aaaa.png');
   

    
    
    

  
